from django.urls import path, re_path, include
from .views import *
from django.http import JsonResponse

def api_welcome(request):
    return JsonResponse({
        'message': 'Welcome to the API',
        'endpoints': {
            'articles': '/api/article/',
            'users': '/api/user/',
            'orders': '/api/order/',
            'login': '/api/login/'
        }
    })

def favicon(request):
    from django.http import HttpResponse
    return HttpResponse(status=204)

urlpatterns = [
    # 基础路由
    path('', api_welcome, name='api_welcome'),
    path('favicon.ico', favicon, name='favicon'),

    # Article 模块
    path('api/article/', include([
        path('list', ArticleList.as_view(), name='article_list'),
        path('add', ArticleList.as_view(), name='article_add'),
        path('search', ArticleSearch.as_view(), name='article_search'),
        path('delete/<int:id>', ArticleDetail.as_view(), name='article_delete'),
        path('update/<int:id>', ArticleDetail.as_view(), name='article_update'),
    ])),

    # LoginUser 模块
    path('api/login/', include([
        path('login', LoginView.as_view(), name='login'),
        path('register', RegisterView.as_view(), name='register'),
        path('list', UserListView.as_view(), name='user_list'),
        path('search', LoginUserSearch.as_view(), name='login_user_search'),
    ])),

    # Order 模块
    path('api/order/', include([
        path('orderList', OrderView.as_view(), name='order_list'),
        path('add', OrderView.as_view(), name='order_add'),
        path('search', OrderSearch.as_view(), name='order_search'),
        path('delete/<int:id>', OrderDetailView.as_view(), name='order_delete'),
        path('update', OrderDetailView.as_view(), name='order_update'),
    ])),

    # User 模块
    path('api/user/', include([
        path('userList', UserView.as_view(), name='user_list'),
        path('add', UserView.as_view(), name='user_add'),
        path('search', UserSearch.as_view(), name='user_search'),
        path('delete/<int:id>', UserDetailView.as_view(), name='user_delete'),
        path('update/<int:id>', UserDetailView.as_view(), name='user_update'),
    ])),

    # 自定义路由
    path('hybridaction/zybTrackerStatisticsAction', 
        ZybTrackerStatisticsAction.as_view(),
        name='zyb_tracker_statistics_action'),
]
